package game.players.states;

import java.util.Timer;

import utils.tasks.ExpireTask;
import game.Goal3;
import game.ball.SoccerBall;
import game.players.SoccerPlayer;

import com.uqbar.vainilla.DeltaState;

public abstract class PassingPlayer extends WithBall {
	
	private Timer timer;
	private SoccerPlayer targetPlayer;
	
	protected static final int SPEED = Goal3.PASS_SPEED;

	public PassingPlayer(SoccerPlayer player, SoccerPlayer target) {
		super(player);
		this.setTargetPlayer(target);
		
		this.setTimer(new Timer());
		this.getTimer().schedule(new ExpireTask<PassingPlayer>(this) {

			@Override
			public void run() {
				this.getCallBackClass().executePass();
			}
		}, 200);
	}

	@Override
	public void update(DeltaState deltaState) {
		// No aplica
	}
	
	protected void executePass() {
		if (!this.getPlayer().getScene().isBallOnGame())
			this.getPlayer().getScene().setBallOnGame(true);

		SoccerBall ball = this.getPlayer().getScene().getSoccerBall();
		double i = this.getTargetPlayer().getX() - this.getPlayer().getX();
		double j = this.getTargetPlayer().getY() - this.getPlayer().getY();

		ball.roll(SPEED, i, j);
		this.changeToStationary();
	}
	
	protected abstract void changeToStationary();
	
	
	
	
	

	public Timer getTimer() {
		return timer;
	}

	public void setTimer(Timer timer) {
		this.timer = timer;
	}

	public SoccerPlayer getTargetPlayer() {
		return targetPlayer;
	}

	public void setTargetPlayer(SoccerPlayer targetPlayer) {
		this.targetPlayer = targetPlayer;
	}

}
